//
//  at24cxx.h
//  electronic_clock
//
//  Created by fukai on 2018/10.
//  Copyright © 2018年 赛博智能车实验室. All rights reserved.
//

#ifndef at24cxx_h
#define at24cxx_h

#include "stm32f10x.h"

//定义IIC通道以及引脚
#define IIC_RCC			RCC_APB2Periph_GPIOB
#define IIC_GPIO		GPIOB
#define IIC_SCL_Pin		GPIO_Pin_4
#define IIC_SDA_Pin		GPIO_Pin_3


//数据线输入输出方向设置
#define SDA_DIR_IN()  	{GPIOB->CRL&=0xFFFF0FFF;GPIOB->CRL|=8<<12;}	//PB3
#define SDA_DIR_OUT() 	{GPIOB->CRL&=0xFFFF0FFF;GPIOB->CRL|=3<<12;}	//PB3

//主机发送时，时钟线和数据线的电平
#define SCL_H()		GPIO_SetBits(IIC_GPIO,IIC_SCL_Pin)
#define SCL_L()		GPIO_ResetBits(IIC_GPIO,IIC_SCL_Pin)
#define SDA_H()		GPIO_SetBits(IIC_GPIO,IIC_SDA_Pin)
#define SDA_L()		GPIO_ResetBits(IIC_GPIO,IIC_SDA_Pin)

//主机读取数据线状态
#define SDA_READ()	GPIO_ReadInputDataBit(IIC_GPIO,IIC_SDA_Pin)



//EEPROM器件地址
#define AT24C02_WRITE_ADDR	0xA0	//写器件地址
#define AT24C02_READ_ADDR	0xA1	//读器件地址


void At24cxxIICInit(void);//AT24CXX初始化IIC接口
void At24cxxWriteData(unsigned char data_addr, unsigned int data);//写数据
unsigned int At24cxxReadData(unsigned char data_addr);//读数据

#endif


